#pragma once
#include <irrlicht.h>

class EventManager : public irr::IEventReceiver 
{
private:
	bool m_Keys[irr::KEY_KEY_CODES_COUNT];
	bool m_MouseKeys[3];
	irr::core::vector3df m_MousePosition;

	irr::scene::ICameraSceneNode *m_Camera;

public:

	EventManager(irr::scene::ICameraSceneNode *cam)
    {
        for (irr::u32 i=0; i<irr::KEY_KEY_CODES_COUNT; ++i)
			m_Keys[i] = false;
		for (irr::u32 i=0; i < 3; ++i)
			m_MouseKeys[i];

		m_Camera = cam;
    }

	virtual bool OnEvent(const irr::SEvent& event)
    {
		if (event.EventType == irr::EET_KEY_INPUT_EVENT)
		{
			m_Keys[event.KeyInput.Key] = event.KeyInput.PressedDown;
		}
		else if (event.EventType == irr::EET_MOUSE_INPUT_EVENT)
		{
			m_MouseKeys[0] = event.MouseInput.isLeftPressed();
			m_MouseKeys[1] = event.MouseInput.isMiddlePressed();
			m_MouseKeys[2] = event.MouseInput.isRightPressed();
			m_MousePosition.X = event.MouseInput.X;
			m_MousePosition.Y = event.MouseInput.Y;
		}
		if(m_Camera) {
			return m_Camera->OnEvent(event);
		}
        return false;
    }

	bool getKey(int i)
	{
		return m_Keys[i];
	}

	bool getMouseKey(int i)
	{
		return m_MouseKeys[i];
	}

};